package net.togogo.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@Controller
public class HelloController {

    //localhost:8080/hello.do
    @RequestMapping(value = "/hello",method = RequestMethod.GET)
    public String sayHello(){
        System.out.println("==============HelloController.sayHello()==========");
        return "/Hello.html";
    }

    //localhost:8080/word.do
/*    @RequestMapping(value = "/word",method = RequestMethod.GET)
    public String sayWord(){
        System.out.println("===========HelloController.sayWord================");
        return "index";
    }*/

    //参数传递
    //localhost:8080/name.do?name=qianduoduo
    @RequestMapping(value = "/name",method = RequestMethod.GET)
    public String sayName(String name){
        System.out.println("name = " + name);
        return "success.html";
    }

    //参数判断
    //localhost:8080/age.do?age=18
    @RequestMapping(value = "/age",method = RequestMethod.GET)
    public String sayAge(int age){
        System.out.println("age = " + age);
        if (age!=18){
            return "/no18.html";
        }
        return "/success.html";
    }

    //多个参数
    @RequestMapping(value = "/login",method = RequestMethod.GET)
    public String sayLogin(String name,String password){
        System.out.println("name = " + name);
        System.out.println("password = " + password);
        return "success.html";
    }

    @RequestMapping(value = "/api",method = RequestMethod.GET)
    public String get(HttpServletRequest request, HttpServletResponse response, HttpSession session){
        System.out.println("request = " + request);
        System.out.println("response = " + response);
        System.out.println("session = " + session);
        return "success.html";
    }
}
